package ch1;

import java.util.*;

public class SetTest {

	public static void main(String[] args) {
		String sss = null;
		Set s = new HashSet();
		s.add("小小");
		s.add(29);
		s.add("蚂蚁");
		s.add("小鹿");
		s.add("小小");

		System.out.println(s.size());
		System.out.println(s);
		System.out.println(">>>>>>>>>>>>>>>");
		// 迭代
		// 1:转换成数组
		Object[] ar = s.toArray();
		for (int i = 0; i < ar.length; i++) {
			System.out.println(ar[i]);
		}
		System.out.println(">>>>>>2:");
		// 获得迭代器：
		Iterator ir = s.iterator();
		while (ir.hasNext()) {
			Object o = ir.next();
			System.out.print(o + "\t");
		}
		System.out.println(">>>>>3:");
		// 增强for循环（Set,List,数组）
		for (Object o : s) {
			System.out.print(o + " ");
		}
		// int[] f = { 1, 4, 6, 9, 100 };
		// for (int i : f)
		// System.out.println(i);
	}

}
